package com.aftersale.platform.mapper;

import com.aftersale.platform.entity.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {

    @Select("SELECT id, username, password, UPPER(role) as role FROM users WHERE username = #{username}")
    User findByUsername(String username);

    @Select("SELECT id, username, password, role FROM users WHERE id = #{id}")
    User findById(Integer id);

    @Select("SELECT username FROM users WHERE id = #{id}")
    String findUsernameById(Integer id);

    @Insert("INSERT INTO users (username, password, role) VALUES (#{username}, #{password}, #{role})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void save(User user);

    @Update("UPDATE users SET username = #{username}, password = #{password}, role = #{role}, updated_at = CURRENT_TIMESTAMP WHERE id = #{id}")
    void update(User user);

    @Delete("DELETE FROM users WHERE id = #{id}")
    void delete(Integer id);
}